package com.example.midprojcampusspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.midprojcampusspringboot.domain.entity.TManagerActivity;
import com.example.midprojcampusspringboot.domain.entity.TManagerClass;
import com.example.midprojcampusspringboot.domain.entity.TTeacherClass;
import com.example.midprojcampusspringboot.domain.entity.TTeachingStudentInClass;
import com.example.midprojcampusspringboot.domain.params.ClassAddStudentsParams;
import com.example.midprojcampusspringboot.mapper.ActivityMapper;
import com.example.midprojcampusspringboot.mapper.ClassAddStudentsMapper;
import com.example.midprojcampusspringboot.mapper.ClassMapper;
import com.example.midprojcampusspringboot.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ClassServiceImpl extends ServiceImpl<ClassMapper, TManagerClass> implements ClassService {

    @Autowired
    private ClassMapper classMapper;
    @Autowired
    private ClassAddStudentsMapper tTeachingStudentInClassMapper;

    /**
     * 4.为教学班级配置老师
     *
     **/
    @Override
    public boolean configTeacher(TTeacherClass tTeacherClass) {
        return classMapper.configTeacher(tTeacherClass);
    }

    /**
     * 3.添加学员或者添加学员列表
     *
     **/
    @Override
    public boolean addStudent(ClassAddStudentsParams params) {
        // 创建 TTeachingStudentInClass 实体列表
        List<TTeachingStudentInClass> studentInClassList = params.getStudentIds().stream()
                .map(studentId -> new TTeachingStudentInClass(params.getClassId(), studentId, params.getId()))
                .collect(Collectors.toList());

        // 批量插入到数据库
        int result = tTeachingStudentInClassMapper.insertBatch(studentInClassList);
        return result > 0 ? true : false;
    }
}
